/**
 * nov core
 */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD
        define(['jquery'], factory);
    } else if (typeof exports === 'object') {
        // CommonJS
        factory(require('jquery'));
    } else {
        // Browser globals
        factory(jQuery);
    }
}(function ($) {

    /**
     * 原型式继承
     */
    if (!Object.create) {
        Object.create = function (object) {
            var F = function () {
            };
            F.prototype = object;
            return new F;
        };
    }

    /**
     * 遍历数组,执行函数
     */
    if (!Array.prototype.forEach) {
        Array.prototype.forEach = function (fn) {
            for (var i = 0, len = this.length; i < len; i++) {
                fn(this[i], i, this);
            }
        };
    }

    /**
     * 遍历数组,过滤选项
     */
    if (!Array.prototype.filter) {
        Array.prototype.filter = function (fn) {
            var result = [];
            for (var i = 0, len = this.length; i < len; i++) {
                if (fn(this[i], i, this)) {
                    result.push(this[i]);
                }
            }
            return result;
        };
    }

    /**
     * 遍历数组,返回规则匹配的数组
     */
    if (!Array.prototype.map) {
        Array.prototype.map = function (fn) {
            var result = [];
            for (var i = 0, len = this.length; i < len; i++) {
                result.push(fn(this[i], i, this));
            }
            return result;
        };
    }

    /**
     * 遍历数组,如果按照规则所有项返回true，则返回true
     */
    if (!Array.prototype.every) {
        Array.prototype.every = function (fn) {
            var bool = true;
            for (var i = 0, len = this.length; i < len; i++) {
                if (fn(this[i], i, this) == false) {
                    bool = false;
                    break;
                }
            }
            return bool;
        };
    }

    /**
     * 遍历数组,如果按照规则有一个选项返回true，则返回true
     */
    if (!Array.prototype.some) {
        Array.prototype.some = function (fn) {
            var bool = false;
            for (var i = 0, len = this.length; i < len; i++) {
                if (fn(this[i], i, this) == true) {
                    bool = true;
                    break;
                }
            }
            return bool;
        };
    }

    /**
     * 绑定环境
     */
    if (typeof Function.prototype.bind !== 'function') {
        Function.prototype.bind = function (context) {
            var fn = this;
            var args = [];
            for (var i = 1, len = arguments.length; i < len; i++) {
                args.push(arguments[i]);
            }

            return function () {
                for (var j = 1, len = arguments.length; j < len; j++) {
                    args.push(arguments[j]);
                }
                return fn.apply(context, args);
            };
        };
    }

    if (!Function.prototype.bind) {
        Function.prototype.bind = function (oThis) {
            if (typeof this !== "function") {
                throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
            }
            var aArgs = Array.prototype.slice.call(arguments, 1),
                fToBind = this,
                fNOP = function () {
                },
                fBound = function () {
                    return fToBind.apply(this instanceof fNOP && oThis
                            ? this
                            : oThis,
                        aArgs.concat(Array.prototype.slice.call(arguments)));
                };
            fNOP.prototype = this.prototype;
            fBound.prototype = new fNOP();
            return fBound;
        };
    }

    $.fn.nov = $.fn.nov || {};
    $.nov = $.nov || {};
    $.extend($.nov, {
        finger: new window.Fingerprint2()
    });
}));
